/*
 * module_test.c
 *
 * Copyright (C) 2012 - Dr.NP
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Test utils for LUA
 * 
 * @package modules::test
 * @author Dr.NP <np@bsgroup.org>
 * @update 09/28/2012
 * @changelog 
 *      [09/28/2012] - Creation
 */

#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "bsp-ext.h"

#include "module_test.h"

static int test_object(lua_State *s)
{
    if (!s || lua_gettop(s) < 1)
    {
        return 0;
    }

    if (!lua_istable(s, -1))
    {
        return 0;
    }

    BSP_OBJECT *obj = new_object();
    object_from_lua(obj, s, -1);

    debug_object(obj);

    object_to_lua(obj, s);
    
    return 1;
}

int bsp_module_test(lua_State *s)
{
    lua_pushcfunction(s, test_object);
    lua_setglobal(s, "bsp_test_object");
    
    lua_settop(s, 0);
    
    return 0;
}
